<?php

namespace Member\Controller;

/**
 * 会员设置 控制器
 *
 * @since 1.0 <2017-3-27> SoChishun <14507247@qq.com> Added.
 */
class MemberSettings extends AppbaseController {

    // 2016-4-21
    public function editView($where) {
        $mDict = new \XWAM\Model\UserDictModel();
        $data = $mDict->where($where)->find();
        if (!$data) {
            $mDict->add($where);
            $data = $mDict->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        if (!empty($data['content'])) {
            $data = json_decode($data['content'], true);
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        $this->display();
    }

    public function edit() {
        $this->editView(array('title' => 'MEMBER-BASE-SETTINGS', 'conf_group' => 'MEMBER-SETTINGS'));
    }

    public function integral() {
        $this->editView(array('title' => 'MEMBER-INTEGRAL-SETTINGS', 'conf_group' => 'MEMBER-SETTINGS'));
    }

    public function editSave() {
        $data = I('post.');
        $str = json_encode($data);
        $mSite = new \XWAM\Model\UserDictModel();
        $data2 = array('content' => $str, 'id' => $data['id']);
        $result = $mSite->save($data2);
        $this->dialogJump($result['status'], $result['info']);
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = ACTION_NAME;
        }
        $data = array(
            'edit' => array('title' => '基本设置', 'url' => 'edit', 'active' => ''),
            'integral' => array('title' => '积分规则', 'url' => 'integral', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
